package com.wanpinghui.supplier.object.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wanpinghui.supplier.R;
import com.wanpinghui.supplier.utils.WTimeUtil;
import com.yunshl.yunshllibrary.recyclerview.BaseRecyclerViewAdapter;

/***
 * 功能描述:
 * 作者:qiujialiu
 * 时间:2017/11/29
 ***/

public class ObjectDynamicAdapter extends BaseRecyclerViewAdapter<ObjectDynamicAdapter.ObjectDynamicBean, ObjectDynamicAdapter.DynamicHolder> {
    public ObjectDynamicAdapter(Context context) {
        super(context);
    }

    @Override
    public DynamicHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_lv_objectdetail_dynamic, null);
        return new DynamicHolder(view);
    }

    @Override
    public void onBindViewHolder(DynamicHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.textViewName.setText(datas.get(position).name);
        holder.textViewContent.setText(datas.get(position).content);
        holder.textViewTime.setText(WTimeUtil.getTimeShowStr(datas.get(position).time));
        holder.imageViewAvatar.setImageResource(datas.get(position).icon);
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    class DynamicHolder extends RecyclerView.ViewHolder {
        TextView textViewName;
        ImageView imageViewAvatar;
        TextView textViewContent;
        TextView textViewTime;

        public DynamicHolder(View itemView) {
            super(itemView);
            textViewName = (TextView) itemView.findViewById(R.id.tv_title);
            textViewContent = (TextView) itemView.findViewById(R.id.tv_content);
            textViewTime = (TextView) itemView.findViewById(R.id.tv_time);
            imageViewAvatar = (ImageView) itemView.findViewById(R.id.iv_avatar);
            itemView.setLayoutParams(new GridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        }
    }

    public static class ObjectDynamicBean {
        public int icon;
        public String name;
        public String content;
        public long time;
    }
}
